<template>
	<view>
		<uni-nav-bar @clickLeft="$tab.back()" fixed="true" left-icon="left" :title="title" statusBar="true"
			:border="false" />
			
		<view class="mt-20 bg-FFF px-20 py-28" v-if="title == '待持鹿票'">
			消费总金额:{{price}}
		</view>

		<s-pull-scroll ref="pullScroll" :pullDown="pullDown" :pullUp="loadData" :fixed="false">
			<view class="bg-FFF mt-24 px-20 py-28" v-for="(item,index) in list" :key="index" @click="itemClick(item)">
				<view class="flex items-center justify-between">
					<view>
						<view class="text-28">
							{{item.useChannel}}
						</view>
						<view class="text-24 mt-24 text-gray">
							{{item.createTime}}
						</view>
					</view>
					<view class="text-36" :style="{color:item.payment==1 ? '#02CE8A' : '#F41717'}">
						{{item.payment==1 ? '+'+item.amount : '-'+item.amount}}
					</view>
				</view>
			</view>
		</s-pull-scroll>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: "",
				title: "",
				list: [],
				price:""
			};
		},
		onLoad(e) {
			this.id = e.id
			this.title = e.title
			this.refresh()
		},
		methods: {
			refresh() {
				this.$nextTick(() => {
					this.$refs.pullScroll.refresh();
				});
			},
			pullDown(pullScroll) {
				setTimeout(() => {
					this.loadData(pullScroll);
				}, 200);
			},
			loadData(pullScroll) {
				setTimeout(async () => {
					if (pullScroll.page == 1) {
						this.list = [];
					}

					const res = await this.$Api.user.lncomeList({
						currencyType: this.id,
						pageSize: 10,
						pageNum: pullScroll.page 
					})

					console.log(res, '货币记录')
					
					if(this.title == '待持鹿票'){
						this.price = res.data.daichulupiaoAmount
					}

					this.list = this.list.concat(res.data.lncomeLogList.rows || []);
					if(this.list.length == 0){
						pullScroll.empty()
					}

					if (this.list.length >= res.data.lncomeLogList.total) {
						pullScroll.finish();
					} else {
						pullScroll.success();
					}
				}, 500);
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f8f8f8;
	}
</style>